﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.OleDb;
using System.Text.RegularExpressions;

public partial class Unit3_Session1 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnAddHotel_Click(object sender, EventArgs e)
    {
        string file = string.Empty;
        string fileName = string.Empty;
        Guid guid = Guid.NewGuid();

        if (fleUploadPicture.HasFile)
        {
            fileName = "images/" + guid + ".jpg";
            file = Request.MapPath("images/") + guid + ".jpg";
            fleUploadPicture.SaveAs(file);

            OleDbConnection oleDBconn = new OleDbConnection(ConfigurationManager.ConnectionStrings["HotelsConnectionString"].ToString());
            string sql = "Insert into Hotels(HotelName,HotelUrl, Picture, HotelDescription, Ratings, Traveller) Values(@f1,@f2,@f3, @f4, @f5, @f6)";
            OleDbCommand cmd = new OleDbCommand(sql, oleDBconn);
            cmd.CommandType = System.Data.CommandType.Text;
            cmd.Parameters.AddWithValue("@f1", txtHotelName.Text);
            cmd.Parameters.AddWithValue("@f2", txtHotelUrl.Text);
            cmd.Parameters.AddWithValue("@f3", fileName);
            cmd.Parameters.AddWithValue("@f4", txtHotelDescription.Text);
            cmd.Parameters.AddWithValue("@f5", rdoRatings.SelectedValue);
            cmd.Parameters.AddWithValue("@f5", User.Identity.Name);
            oleDBconn.Open();
            cmd.ExecuteNonQuery();
        }


    }
}